﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Text;
using NHibernate.Criterion;
using Common;
namespace Web.helper
{
    public static class HtmlSelect
    {


        #region HtmlHelper
        /// <summary>
        /// 课程
        /// </summary>
        /// <param name="helper"></param>
        /// <returns></returns>
        public static string select_lesson(this HtmlHelper helper, string name = "txt_lesson")
        {
            return Lesson(name);
        }

        /// <summary>
        /// 类目
        /// </summary>
        /// <param name="helper"></param>
        /// <returns></returns>
        public static string select_lessonType(this HtmlHelper helper, string name = "txt_lessonType")
        {
            return LessonType(name);
        }

        public static string select_lessonType2(this HtmlHelper helper, string name = "txt_lessonType")
        {
            return LessonType2(name);
        } 

        /// <summary>
        /// 系列
        /// </summary>
        /// <param name="helper"></param>
        /// <returns></returns>
        public static string select_lessonList(this HtmlHelper helper, string name = "txt_lessonList")
        {
            return LessonList(name);
        }


        /// <summary>
        /// 讲师
        /// </summary>
        /// <param name="helper"></param>
        /// <returns></returns>
        public static string select_Teacher(this HtmlHelper helper, string name = "txt_teacher")
        {
            return Teacher(name);
        }

        public static string select_Groups(this HtmlHelper helper, string name = "txt_powerlist")
        {
            return Groups(name);
        }
        #endregion

        #region 基础方法





        public static string Lesson(string name)
        {
            DAO.BLL.B_lesson b_lesson = new DAO.BLL.B_lesson();
            List<SearchTemplate> st = new List<SearchTemplate>() 
            {
                new SearchTemplate(){key="is_del",value=0,searchType=EnumBase.SearchType.Eq}
            };
            var list = b_lesson.GetList(st, null);
            StringBuilder sb = new StringBuilder();
            sb.Append("<select id=\"" + name + "\" name=\"" + name + "\" class=\"selectpicker show-tick form-control\" data-live-search=\"true\">");
            sb.Append("<optgroup label=\"默认选择\">");
            sb.Append("<option value=\"0\" selected = \"true\">无</option>");
            foreach (var item in list)
            {
                sb.Append("<option value=" + item.ID + ">" + item.lessonname + "</option>");   
            }
            sb.Append("</optgroup>");
            sb.Append("</select>");
            return sb.ToString();
        }


        public static string LessonType(string name)
        {
            DAO.BLL.B_lessoncategory b_lc = new DAO.BLL.B_lessoncategory();
            List<SearchTemplate> st = new List<SearchTemplate>() 
            {
                new SearchTemplate(){key="is_del",value=0,searchType=EnumBase.SearchType.Eq},
                new SearchTemplate(){key="level",value=0,searchType=EnumBase.SearchType.Eq}
            };
            var list = b_lc.GetList(st, null);
            StringBuilder sb = new StringBuilder();
            sb.Append("<select id=\"" + name + "\" name=\"" + name + "\" class=\"selectpicker show-tick form-control\" data-live-search=\"true\">");
            sb.Append("<optgroup label=\"默认选择\">");
            sb.Append("<option value=\"0\" selected = \"true\">无</option>");
            foreach (var item in list)
            {
                sb.Append("<option value=" + item.ID + ">" + item.name + "</option>");
                st = new List<SearchTemplate>() 
                {
                    new SearchTemplate(){key="is_del",value=0,searchType=EnumBase.SearchType.Eq},
                    new SearchTemplate(){key="level",value=1,searchType=EnumBase.SearchType.Eq},
                    new SearchTemplate(){key="parentnode",value=item.ID,searchType=EnumBase.SearchType.Eq}
                };
                var list2 = b_lc.GetList(st, null);
                foreach (var item2 in list2)
                {
                    sb.Append("<option value=" + item2.ID + ">" + "&nbsp;&nbsp;&nbsp;&nbsp;" + item2.name + "</option>");
                }
            }
            sb.Append("</optgroup>");
            sb.Append("</select>");
            return sb.ToString();
        }


        public static string LessonType2(string name)
        {
            DAO.BLL.B_lessoncategory b_lc = new DAO.BLL.B_lessoncategory();
            List<SearchTemplate> st = new List<SearchTemplate>() 
            {
                new SearchTemplate(){key="is_del",value=0,searchType=EnumBase.SearchType.Eq},
                new SearchTemplate(){key="level",value=0,searchType=EnumBase.SearchType.Eq}
            };
            var list = b_lc.GetList(st, null);
            StringBuilder sb = new StringBuilder();
            sb.Append("<select id=\"" + name + "\" name=\"" + name + "\" class=\"selectpicker show-tick form-control\" data-live-search=\"true\">");
            sb.Append("<optgroup label=\"默认选择\">");
            sb.Append("<option value=\"0\" selected = \"true\">无</option>");
            foreach (var item in list)
            {
                sb.Append("<option value=" + item.ID + ">" + item.name + "</option>");
                st = new List<SearchTemplate>() 
                {
                    new SearchTemplate(){key="is_del",value=0,searchType=EnumBase.SearchType.Eq},
                    new SearchTemplate(){key="level",value=1,searchType=EnumBase.SearchType.Eq},
                    new SearchTemplate(){key="parentnode",value=item.ID,searchType=EnumBase.SearchType.Eq}
                };
                var list2 = b_lc.GetList(st, null);
                foreach (var item2 in list2)
                {
                    sb.Append("<option value=" + item2.ID + ">" + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + item2.name + "</option>");
                    st = new List<SearchTemplate>();
                    st.Add(new SearchTemplate() { key = "is_del", value = 0, searchType = EnumBase.SearchType.Eq });
                    st.Add(new SearchTemplate() { key = "level", value = 2, searchType = EnumBase.SearchType.Ge });
                    st.Add(new SearchTemplate() { key = "parentnode", value = item2.ID, searchType = EnumBase.SearchType.Eq });
                    //三级
                    var list_nt3 = b_lc.GetList(st, null);
                    foreach (var item3 in list_nt3)
                    {
                        sb.Append("<option value=" + item3.ID + ">" + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + item3.name + "</option>");
                    }
                }
            }
            sb.Append("</optgroup>");
            sb.Append("</select>");
            return sb.ToString();
        }

        public static string LessonList(string name)
        {
            DAO.BLL.B_lessonseries b_ls = new DAO.BLL.B_lessonseries();
            List<SearchTemplate> st = new List<SearchTemplate>() 
            {
                new SearchTemplate(){key="is_del",value=0,searchType=EnumBase.SearchType.Eq}
            };
            var list = b_ls.GetList(st, null);
            StringBuilder sb = new StringBuilder();
            sb.Append("<select id=\"" + name + "\" name=\"" + name + "\" class=\"selectpicker show-tick form-control\" data-live-search=\"true\">");
            sb.Append("<optgroup label=\"默认选择\">");
            sb.Append("<option value=\"0\" selected = \"true\">无</option>");
            foreach (var item in list)
            {
                sb.Append("<option value=" + item.ID + ">" + item.name + "</option>");
            }
            sb.Append("</optgroup>");
            sb.Append("</select>");
            return sb.ToString();
        }



        public static string Teacher(string name)
        {
            DAO.BLL.B_teacher b_teacher = new DAO.BLL.B_teacher();
            List<SearchTemplate> st = new List<SearchTemplate>() 
            {
                new SearchTemplate(){key="is_del",value=0,searchType=EnumBase.SearchType.Eq}
            };
            var list = b_teacher.GetList(st, null);
            StringBuilder sb = new StringBuilder();
            sb.Append("<select id=\"" + name + "\" name=\"" + name + "\" class=\"selectpicker show-tick form-control\" data-live-search=\"true\">");
            sb.Append("<optgroup label=\"默认选择\">");
            sb.Append("<option value=\"0\" selected = \"true\">无</option>");
            foreach (var item in list)
            {
                sb.Append("<option value=" + item.ID + ">" + item.name + "</option>");
            }
            sb.Append("</optgroup>");
            sb.Append("</select>");
            return sb.ToString();
        }


        public static string Groups(string name)
        {
            DAO.BLL.B_groups b_group = new DAO.BLL.B_groups();
            List<SearchTemplate> st = new List<SearchTemplate>() 
            {
                new SearchTemplate(){key="is_del",value=0,searchType=EnumBase.SearchType.Eq}
            };
            var list = b_group.GetList(st, null);
            StringBuilder sb = new StringBuilder();
            sb.Append("<select id=\"" + name + "\" name=\"" + name + "\" class=\"selectpicker show-tick form-control\" multiple data-live-search=\"false\">");
            sb.Append("<optgroup label=\"默认选择\">");
            //sb.Append("<option value=\"0\" selected = \"true\">无</option>");
            foreach (var item in list)
            {
                if (item.ID == list[0].ID)
                {
                    sb.Append("<option value=\"" + item.ID + "\" selected = \"true\">" + item.name + "</option>");
                }
                else 
                {
                    sb.Append("<option value=" + item.ID + ">" + item.name + "</option>");
                }
            }
            sb.Append("</optgroup>");
            sb.Append("</select>");
            return sb.ToString();
        }
        #endregion





    }

    public class model
    {
        public int id { get; set; }

        public string name { get; set; }
    }
}

